Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Java String Class Methods

  • The java.lang.String the class contains a number of built-in methods for manipulating strings. We can use these methods to execute actions on String objects such as cutting, concatenating, converting, comparing, and replacing strings.

  • Everything is treated as a String when you submit any form in a window-based, web-based, or mobile application, which makes Java String a powerful concept.





Important methods of String class


Java String length() Methods


The length() method of the String class returns the length of the specified String.


 // Java example of String length() Methods
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint";    
		System.out.println(s.length()); 
   } 
}

Output:

8 


Java String charAt() Method


The charAt() method of the String class returns the character at the given index.


 // Java example of String charAt() Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint";    
		System.out.println(s.charAt(1)); 
   } 
}




Output:

x 

Java String substring Method


The substring method of the String class return the substring from the ith index character to end.


 // Java example of String substring  Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint";    
		System.out.println(s.substring(3)); 
   } 
}

Output:

mDeva 

Java String substring (int start, int end) Method


The substring method of the String class return the substring (int start, int end) from the ith index character to end.


 // Java example of String substring (int start, int end)  Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint";    
		System.out.println(s.substring(3,5)); 
   } 
}



Output:

mD  

Java String concat Method


The concat method of the String class return the concatenates specified string to the end of this string.


 // Java example of String concat Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="Exam"; 
		String s1="Deva";
		System.out.println(s.concat(s1)); 
   } 
}

Output:

DockerTpoint  

Java String indexOf Method


The indexOf method of the String class returns the position of the first instance of the specified string within the given string.


 // Java example of String indexOf Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="Exam Deva"; 
		System.out.println(s.indexOf("Deva")); 
   } 
}



Output:

5  

Java String indexOf (String s, int i) Method


The indexOf (String string, int index) method of the String class returns the first instance of the specified string in the string, starting at the specified index.


 // Java example of String indexOf Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint"; 
		System.out.println(s.indexOf("De",3)); 
   } 
}

Output:

4 

Java String lastIndexOf Method


The lastIndexOf method of the String class the last instance of the specified string, at the specified index, is returned.


 // Java example of String lastIndexOf Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint"; 
		System.out.println(s.indexOf("De")); 
   } 
}



Output:

4 

Java String equals Method


The equals method of the String class the string is compared to the given object.


 // Java example of String equals Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint"; 
		System.out.println(s.equals("DockerTpoint")); 
   } 
}

Output:

true 

Java String equalsIgnoreCase Method


The equalsIgnoreCase method of the String class the string is compared to the given string ignoring case considerations.


 // Java example of String equalsIgnoreCase Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint"; 
		System.out.println(s.equalsIgnoreCase("dockertpoint")); 
   } 
}



Output:

true 

Java String toLowerCase() Method


The toLowerCase() method of the String class Lowercases each character in the String.


 // Java example of String toLowerCase() Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="EXAMDEVA"; 
		System.out.println(s.toLowerCase()); 
   } 
}

Output:

dockertpoint 

Java String toUpperCase() Method


The toUpperCase() method of the String class UpperCase each character in the String.


 // Java example of String toUpperCase() Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="dockertpoint"; 
		System.out.println(s.toUpperCase()); 
   } 
}



Output:

EXAMDEVA 

Java String trim() Method


The trim() method of the String class removes the whitespace at both ends and then returns a copy of the String. The middle whitespaces are unaffected.


 // Java example of String trim() Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="   exam deva   "; 
		System.out.println(s.trim());  // "exam deva"
   } 
}

Output:

exam deva 

Java String replace (char old, char new) Method


The replace method of the String class replaces every instance of old with new to produce a new string.


 // Java example of String replace Method 
public class Main {	
	public static void main(String args[]){  		 
		String s="DockerTpoint"; 
		System.out.println(s.replace('e','d'));  
   } 
}



Output:

ExamDdva 


Java Immutable String Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java

Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.